



<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#FFF">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon.png">

<link rel="icon" type="image/ico" sizes="32x32" href="/blog/images/favicon.ico">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">


<link rel="alternate" type="application/rss+xml" title="凡尘一叶" href="http://fyduyu.gitee.io/blog/rss.xml" />
<link rel="alternate" type="application/atom+xml" title="凡尘一叶" href="http://fyduyu.gitee.io/blog/atom.xml" />
<link rel="alternate" type="application/json" title="凡尘一叶" href="http://fyduyu.gitee.io/blog/feed.json" />

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Mulish:300,300italic,400,400italic,700,700italic%7CFredericka%20the%20Great:300,300italic,400,400italic,700,700italic%7CNoto%20Serif%20JP:300,300italic,400,400italic,700,700italic%7CNoto%20Serif%20SC:300,300italic,400,400italic,700,700italic%7CInconsolata:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="/blog/css/app.css?v=0.2.5">

  
  <meta name="keywords" content="配置" />


<link rel="canonical" href="http://fyduyu.gitee.io/blog/2020/12/23/Druid%E9%85%8D%E7%BD%AE/">



  <title>
Druid配置 - java |
blog = 凡尘一叶</title>
<meta name="generator" content="Hexo 5.3.0"></head>
<body itemscope itemtype="http://schema.org/WebPage">
  <div id="loading">
    <div class="cat">
      <div class="body"></div>
      <div class="head">
        <div class="face"></div>
      </div>
      <div class="foot">
        <div class="tummy-end"></div>
        <div class="bottom"></div>
        <div class="legs left"></div>
        <div class="legs right"></div>
      </div>
      <div class="paw">
        <div class="hands left"></div>
        <div class="hands right"></div>
      </div>
    </div>
  </div>
  <div id="container">
    <header id="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="inner">
        <div id="brand">
          <div class="pjax">
          
  <h1 itemprop="name headline">Druid配置
  </h1>
  
<div class="meta">
  <span class="item" title="创建时间：2020-12-23 15:07:48">
    <span class="icon">
      <i class="ic i-calendar"></i>
    </span>
    <span class="text">发表于</span>
    <time itemprop="dateCreated datePublished" datetime="2020-12-23T15:07:48+08:00">2020-12-23</time>
  </span>
  <span class="item" title="本文字数">
    <span class="icon">
      <i class="ic i-pen"></i>
    </span>
    <span class="text">本文字数</span>
    <span>3.7k</span>
    <span class="text">字</span>
  </span>
  <span class="item" title="阅读时长">
    <span class="icon">
      <i class="ic i-clock"></i>
    </span>
    <span class="text">阅读时长</span>
    <span>3 分钟</span>
  </span>
</div>


          </div>
        </div>
        <nav id="nav">
  <div class="inner">
    <div class="toggle">
      <div class="lines" aria-label="切换导航栏">
        <span class="line"></span>
        <span class="line"></span>
        <span class="line"></span>
      </div>
    </div>
    <ul class="menu">
      <li class="item title"><a href="/blog/" rel="start">blog</a></li>
    </ul>
    <ul class="right">
      <li class="item theme">
        <i class="ic i-sun"></i>
      </li>
      <li class="item search">
        <i class="ic i-search"></i>
      </li>
    </ul>
  </div>
</nav>

      </div>
      <div id="imgs" class="pjax">
        <ul>
          <li class="item" data-background-image="https://tva4.sinaimg.cn/large/6833939bly1giclh5u05ej20zk0m87df.jpg"></li>
          <li class="item" data-background-image="https://tva4.sinaimg.cn/large/6833939bly1giclfb3vzhj20zk0m8wny.jpg"></li>
          <li class="item" data-background-image="https://tva4.sinaimg.cn/large/6833939bly1giclhnx9glj20zk0m8npd.jpg"></li>
          <li class="item" data-background-image="https://tva4.sinaimg.cn/large/6833939bly1gipevarprfj20zk0m8npd.jpg"></li>
          <li class="item" data-background-image="https://tva4.sinaimg.cn/large/6833939bly1giclh0m9pdj20zk0m8hdt.jpg"></li>
          <li class="item" data-background-image="https://tva4.sinaimg.cn/large/6833939bly1gipeyvx1d4j20zk0m8hdt.jpg"></li>
        </ul>
      </div>
    </header>
    <div id="waves">
      <svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
        <defs>
          <path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" />
        </defs>
        <g class="parallax">
          <use xlink:href="#gentle-wave" x="48" y="0" />
          <use xlink:href="#gentle-wave" x="48" y="3" />
          <use xlink:href="#gentle-wave" x="48" y="5" />
          <use xlink:href="#gentle-wave" x="48" y="7" />
        </g>
      </svg>
    </div>
    <main>
      <div class="inner">
        <div id="main" class="pjax">
          
  <div class="article wrap">
    
<div class="breadcrumb" itemscope itemtype="https://schema.org/BreadcrumbList">
<i class="ic i-home"></i>
<span><a href="/blog/">首页</a></span><i class="ic i-angle-right"></i>
<span  class="current" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="/blog/categories/java/" itemprop="item" rel="index" title="分类于 java"><span itemprop="name">java</span></a>
<meta itemprop="position" content="1" /></span>
</div>

    <article itemscope itemtype="http://schema.org/Article" class="post block" lang="zh-CN">
  <link itemprop="mainEntityOfPage" href="http://fyduyu.gitee.io/blog/2020/12/23/Druid%E9%85%8D%E7%BD%AE/">

  <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="image" content="/blog/images/touxiang.jpg">
    <meta itemprop="name" content="杜朝宇">
    <meta itemprop="description" content=", 个人博客&编程笔记">
  </span>

  <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="凡尘一叶">
  </span>

  <div class="body md" itemprop="articleBody">
    

    <h4 id="maven引入"><a class="markdownIt-Anchor" href="#maven引入">#</a> maven 引入</h4>
<figure class="highlight xml"><figcaption data-lang="XML"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment">&lt;!-- 引入 druid --></span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="3"></td><td><pre>    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>com.alibaba<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="4"></td><td><pre>    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>druid<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="5"></td><td><pre>    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">></span></span>1.2.4<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr></table></figure><h4 id="配置druid"><a class="markdownIt-Anchor" href="#配置druid">#</a> 配置 Druid</h4>
<figure class="highlight java"><figcaption data-lang="java"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token annotation punctuation">@Configuration</span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">DruidConfig</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="3"></td><td><pre></pre></td></tr><tr><td data-num="4"></td><td><pre>    <span class="token annotation punctuation">@Bean</span></pre></td></tr><tr><td data-num="5"></td><td><pre>    <span class="token annotation punctuation">@ConfigurationProperties</span><span class="token punctuation">(</span>prefix <span class="token operator">=</span> <span class="token string">"spring.datasource"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="6"></td><td><pre>    <span class="token keyword">public</span> <span class="token class-name">DataSource</span> <span class="token function">getDataSource</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="7"></td><td><pre>        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">DruidDataSource</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="8"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="9"></td><td><pre></pre></td></tr><tr><td data-num="10"></td><td><pre>    <span class="token annotation punctuation">@Bean</span></pre></td></tr><tr><td data-num="11"></td><td><pre>    <span class="token keyword">public</span> <span class="token class-name">ServletRegistrationBean</span> <span class="token function">druidStatViewServlet</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="12"></td><td><pre>        <span class="token comment">//ServletRegistrationBean 提供类的进行注册</span></pre></td></tr><tr><td data-num="13"></td><td><pre>        <span class="token class-name">ServletRegistrationBean</span> servletRegistrationBean <span class="token operator">=</span></pre></td></tr><tr><td data-num="14"></td><td><pre>                <span class="token keyword">new</span> <span class="token class-name">ServletRegistrationBean</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">StatViewServlet</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">"/druid/*"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="15"></td><td><pre>        <span class="token comment">// 添加初始化参数：initParams</span></pre></td></tr><tr><td data-num="16"></td><td><pre>        <span class="token comment">// 白名单：</span></pre></td></tr><tr><td data-num="17"></td><td><pre>        servletRegistrationBean<span class="token punctuation">.</span><span class="token function">addInitParameter</span><span class="token punctuation">(</span><span class="token string">"allow"</span><span class="token punctuation">,</span> <span class="token string">"127.0.0.1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="18"></td><td><pre>        <span class="token comment">//IP 黑名单（同时存在时，deny 优先于 allow）</span></pre></td></tr><tr><td data-num="19"></td><td><pre>        <span class="token comment">// 如果满足 deny，就提示：sorry，you are not permitted to view this page</span></pre></td></tr><tr><td data-num="20"></td><td><pre>        servletRegistrationBean<span class="token punctuation">.</span><span class="token function">addInitParameter</span><span class="token punctuation">(</span><span class="token string">"deny"</span><span class="token punctuation">,</span> <span class="token string">"192.168.1.73"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="21"></td><td><pre>        <span class="token comment">// 登录查看信息的账号和密码</span></pre></td></tr><tr><td data-num="22"></td><td><pre>        servletRegistrationBean<span class="token punctuation">.</span><span class="token function">addInitParameter</span><span class="token punctuation">(</span><span class="token string">"loginUsername"</span><span class="token punctuation">,</span> <span class="token string">"admin"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="23"></td><td><pre>        servletRegistrationBean<span class="token punctuation">.</span><span class="token function">addInitParameter</span><span class="token punctuation">(</span><span class="token string">"loginPassword"</span><span class="token punctuation">,</span> <span class="token string">"123456"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="24"></td><td><pre>        servletRegistrationBean<span class="token punctuation">.</span><span class="token function">addInitParameter</span><span class="token punctuation">(</span><span class="token string">"resetEnable"</span><span class="token punctuation">,</span> <span class="token string">"false"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="25"></td><td><pre>        <span class="token keyword">return</span> servletRegistrationBean<span class="token punctuation">;</span></pre></td></tr><tr><td data-num="26"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="27"></td><td><pre></pre></td></tr><tr><td data-num="28"></td><td><pre></pre></td></tr><tr><td data-num="29"></td><td><pre>    <span class="token annotation punctuation">@Bean</span></pre></td></tr><tr><td data-num="30"></td><td><pre>    <span class="token keyword">public</span> <span class="token class-name">FilterRegistrationBean</span> <span class="token function">druidStatFilter</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="31"></td><td><pre>        <span class="token class-name">FilterRegistrationBean</span> filterRegistrationBean <span class="token operator">=</span></pre></td></tr><tr><td data-num="32"></td><td><pre>                <span class="token keyword">new</span> <span class="token class-name">FilterRegistrationBean</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">WebStatFilter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="33"></td><td><pre>        <span class="token comment">// 添加过滤规则</span></pre></td></tr><tr><td data-num="34"></td><td><pre>        filterRegistrationBean<span class="token punctuation">.</span><span class="token function">addUrlPatterns</span><span class="token punctuation">(</span><span class="token string">"/*"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="35"></td><td><pre>        <span class="token comment">// 添加需要忽略的格式信息</span></pre></td></tr><tr><td data-num="36"></td><td><pre>        filterRegistrationBean<span class="token punctuation">.</span><span class="token function">addInitParameter</span><span class="token punctuation">(</span><span class="token string">"exclusions"</span><span class="token punctuation">,</span> <span class="token string">"*.js,*.gif,"</span> <span class="token operator">+</span></pre></td></tr><tr><td data-num="37"></td><td><pre>                <span class="token string">"*.jpg,*.png, *.css,*.ico,/druid/*"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="38"></td><td><pre>        <span class="token keyword">return</span> filterRegistrationBean<span class="token punctuation">;</span></pre></td></tr><tr><td data-num="39"></td><td><pre></pre></td></tr><tr><td data-num="40"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="41"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure><h4 id="springboot-config"><a class="markdownIt-Anchor" href="#springboot-config">#</a> springboot config</h4>
<figure class="highlight properties"><figcaption data-lang=".properties"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment">### db config ###</span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token attr-name">spring.datasource.type</span><span class="token punctuation">=</span><span class="token attr-value">com.alibaba.druid.pool.DruidDataSource</span></pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token attr-name">spring.datasource.driverClassName</span><span class="token punctuation">=</span><span class="token attr-value">org.postgresql.Driver</span></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token attr-name">spring.datasource.url</span><span class="token punctuation">=</span><span class="token attr-value">jdbc:postgresql://localhost:5432/XXX?useUnicode=true&amp;characterEncoding=utf8&amp;curre</span></pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token attr-name">ntSchema</span><span class="token punctuation">=</span><span class="token attr-value">public</span></pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token attr-name">spring.datasource.username</span><span class="token punctuation">=</span><span class="token attr-value">postgres</span></pre></td></tr><tr><td data-num="7"></td><td><pre><span class="token attr-name">spring.datasource.password</span><span class="token punctuation">=</span><span class="token attr-value">XXX</span></pre></td></tr><tr><td data-num="8"></td><td><pre><span class="token attr-name">spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation</span><span class="token punctuation">=</span><span class="token attr-value">true</span></pre></td></tr><tr><td data-num="9"></td><td><pre><span class="token attr-name">spring.jpa.properties.hibernate.dialect</span><span class="token punctuation">=</span><span class="token attr-value">org.hibernate.dialect.PostgreSQLDialect</span></pre></td></tr><tr><td data-num="10"></td><td><pre><span class="token attr-name">spring.jpa.properties.hibernate.hbm2ddl.auto</span><span class="token punctuation">=</span><span class="token attr-value">update</span></pre></td></tr><tr><td data-num="11"></td><td><pre><span class="token comment">#config druid</span></pre></td></tr><tr><td data-num="12"></td><td><pre><span class="token comment">#连接池的设置</span></pre></td></tr><tr><td data-num="13"></td><td><pre><span class="token comment">#初始化时建立物理连接的个数</span></pre></td></tr><tr><td data-num="14"></td><td><pre><span class="token attr-name">spring.datasource.druid.initial-size</span><span class="token punctuation">=</span><span class="token attr-value">5</span></pre></td></tr><tr><td data-num="15"></td><td><pre><span class="token comment">#最小连接池数量</span></pre></td></tr><tr><td data-num="16"></td><td><pre><span class="token attr-name">spring.datasource.druid.min-idle</span><span class="token punctuation">=</span><span class="token attr-value">5</span></pre></td></tr><tr><td data-num="17"></td><td><pre><span class="token comment">#最大连接池数量 maxIdle 已经不再使用</span></pre></td></tr><tr><td data-num="18"></td><td><pre><span class="token attr-name">spring.datasource.druid.max-active</span><span class="token punctuation">=</span><span class="token attr-value">20</span></pre></td></tr><tr><td data-num="19"></td><td><pre><span class="token comment">#获取连接时最大等待时间，单位毫秒</span></pre></td></tr><tr><td data-num="20"></td><td><pre><span class="token attr-name">spring.datasource.druid.max-wait</span><span class="token punctuation">=</span><span class="token attr-value">60000</span></pre></td></tr><tr><td data-num="21"></td><td><pre><span class="token comment">#申请连接的时候检测，如果空闲时间大于 timeBetweenEvictionRunsMillis，执行 validationQuery 检测连接是否有效。</span></pre></td></tr><tr><td data-num="22"></td><td><pre><span class="token attr-name">spring.datasource.druid.test-while-idle</span><span class="token punctuation">=</span><span class="token attr-value">true</span></pre></td></tr><tr><td data-num="23"></td><td><pre><span class="token comment">#既作为检测的间隔时间又作为 testWhileIdel 执行的依据</span></pre></td></tr><tr><td data-num="24"></td><td><pre><span class="token attr-name">spring.datasource.druid.time-between-eviction-runs-millis</span><span class="token punctuation">=</span><span class="token attr-value">60000</span></pre></td></tr><tr><td data-num="25"></td><td><pre><span class="token comment">#销毁线程时检测当前连接的最后活动时间和当前时间差大于该值时，关闭当前连接</span></pre></td></tr><tr><td data-num="26"></td><td><pre><span class="token attr-name">spring.datasource.druid.min-evictable-idle-time-millis</span><span class="token punctuation">=</span><span class="token attr-value">30000</span></pre></td></tr><tr><td data-num="27"></td><td><pre><span class="token comment">#用来检测连接是否有效的 sql 必须是一个查询语句</span></pre></td></tr><tr><td data-num="28"></td><td><pre><span class="token comment">#mysql 中为 select 'x'</span></pre></td></tr><tr><td data-num="29"></td><td><pre><span class="token comment">#oracle 中为 select 1 from dual</span></pre></td></tr><tr><td data-num="30"></td><td><pre><span class="token attr-name">spring.datasource.druid.validation-query</span><span class="token punctuation">=</span><span class="token attr-value">select 'x'</span></pre></td></tr><tr><td data-num="31"></td><td><pre><span class="token comment">#申请连接时会执行 validationQuery 检测连接是否有效，开启会降低性能，默认为 true</span></pre></td></tr><tr><td data-num="32"></td><td><pre><span class="token attr-name">spring.datasource.druid.test-on-borrow</span><span class="token punctuation">=</span><span class="token attr-value">false</span></pre></td></tr><tr><td data-num="33"></td><td><pre><span class="token comment">#归还连接时会执行 validationQuery 检测连接是否有效，开启会降低性能，默认为 true</span></pre></td></tr><tr><td data-num="34"></td><td><pre><span class="token attr-name">spring.datasource.druid.test-on-return</span><span class="token punctuation">=</span><span class="token attr-value">false</span></pre></td></tr><tr><td data-num="35"></td><td><pre><span class="token comment">#当数据库抛出不可恢复的异常时，抛弃该连接</span></pre></td></tr><tr><td data-num="36"></td><td><pre><span class="token attr-name">spring.datasource.druid.exception-sorter</span><span class="token punctuation">=</span><span class="token attr-value">true</span></pre></td></tr><tr><td data-num="37"></td><td><pre><span class="token comment">#是否缓存 preparedStatement,mysql5.5 + 建议开启</span></pre></td></tr><tr><td data-num="38"></td><td><pre><span class="token comment">#spring.datasource.druid.pool-prepared-statements=true</span></pre></td></tr><tr><td data-num="39"></td><td><pre><span class="token comment">#当值大于 0 时 poolPreparedStatements 会自动修改为 true</span></pre></td></tr><tr><td data-num="40"></td><td><pre><span class="token attr-name">spring.datasource.druid.max-pool-prepared-statement-per-connection-size</span><span class="token punctuation">=</span><span class="token attr-value">20</span></pre></td></tr><tr><td data-num="41"></td><td><pre><span class="token comment">#配置扩展插件</span></pre></td></tr><tr><td data-num="42"></td><td><pre><span class="token attr-name">spring.datasource.druid.filters</span><span class="token punctuation">=</span><span class="token attr-value">stat,wall</span></pre></td></tr><tr><td data-num="43"></td><td><pre><span class="token comment">#通过 connectProperties 属性来打开 mergeSql 功能；慢 SQL 记录</span></pre></td></tr><tr><td data-num="44"></td><td><pre><span class="token attr-name">spring.datasource.druid.connection-properties</span><span class="token punctuation">=</span><span class="token attr-value">druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500</span></pre></td></tr><tr><td data-num="45"></td><td><pre><span class="token comment">#合并多个 DruidDataSource 的监控数据</span></pre></td></tr><tr><td data-num="46"></td><td><pre><span class="token attr-name">spring.datasource.druid.use-global-data-source-stat</span><span class="token punctuation">=</span><span class="token attr-value">true</span></pre></td></tr><tr><td data-num="47"></td><td><pre><span class="token comment">#设置访问 druid 监控页的账号和密码，默认没有</span></pre></td></tr><tr><td data-num="48"></td><td><pre><span class="token comment">#spring.datasource.druid.stat-view-servlet.login-username=admin</span></pre></td></tr><tr><td data-num="49"></td><td><pre><span class="token comment">#spring.datasource.druid.stat-view-servlet.login-password=admin</span></pre></td></tr><tr><td data-num="50"></td><td><pre></pre></td></tr><tr><td data-num="51"></td><td><pre><span class="token comment">### mybatis config ###</span></pre></td></tr><tr><td data-num="52"></td><td><pre><span class="token attr-name">mybatis.config-locations</span><span class="token punctuation">=</span><span class="token attr-value">classpath:mybatis/mybatis-config.xml</span></pre></td></tr><tr><td data-num="53"></td><td><pre><span class="token attr-name">mybatis.mapper-locations</span><span class="token punctuation">=</span><span class="token attr-value">classpath:mybatis/mapper/*.xml</span></pre></td></tr><tr><td data-num="54"></td><td><pre><span class="token attr-name">mybatis.type-aliases-package</span><span class="token punctuation">=</span><span class="token attr-value">com.jrsc.supervisor.model</span></pre></td></tr><tr><td data-num="55"></td><td><pre><span class="token comment">### log config ###</span></pre></td></tr><tr><td data-num="56"></td><td><pre><span class="token attr-name">logging.config</span><span class="token punctuation">=</span><span class="token attr-value">classpath:logback-spring.xml</span></pre></td></tr></table></figure>
      <div class="tags">
          <a href="/blog/tags/%E9%85%8D%E7%BD%AE/" rel="tag"><i class="ic i-tag"></i> 配置</a>
      </div>
  </div>

   <footer>

    <div class="meta">
  <span class="item">
    <span class="icon">
      <i class="ic i-calendar-check"></i>
    </span>
    <span class="text">更新于</span>
    <time title="修改时间：2020-12-25 14:46:29" itemprop="dateModified" datetime="2020-12-25T14:46:29+08:00">2020-12-25</time>
  </span>
  <span id="2020/12/23/Druid配置/" class="item leancloud_visitors" data-flag-title="Druid配置" title="阅读次数">
      <span class="icon">
        <i class="ic i-eye"></i>
      </span>
      <span class="text">阅读次数</span>
      <span class="leancloud-visitors-count"></span>
      <span class="text">次</span>
  </span>
</div>

      
<div class="reward">
  <button><i class="ic i-heartbeat"></i> 赞赏</button>
  <p>请我喝[茶]~(￣▽￣)~*</p>
  <div id="qr">
      
      <div>
        <img data-src="/blog/images/wechatpay.png" alt="杜朝宇 微信支付">
        <p>微信支付</p>
      </div>
      
      <div>
        <img data-src="/blog/images/alipay.png" alt="杜朝宇 支付宝">
        <p>支付宝</p>
      </div>
      
      <div>
        <img data-src="/blog/images/paypal.png" alt="杜朝宇 贝宝">
        <p>贝宝</p>
      </div>
  </div>
</div>

      

<div id="copyright">
<ul>
  <li class="author">
    <strong>本文作者： </strong>杜朝宇 <i class="ic i-at"><em>@</em></i>凡尘一叶
  </li>
  <li class="link">
    <strong>本文链接：</strong>
    <a href="http://fyduyu.gitee.io/blog/2020/12/23/Druid%E9%85%8D%E7%BD%AE/" title="Druid配置">http://fyduyu.gitee.io/blog/2020/12/23/Druid配置/</a>
  </li>
  <li class="license">
    <strong>版权声明： </strong>本站所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzQuMC9kZWVkLnpo"><i class="ic i-creative-commons"><em>(CC)</em></i>BY-NC-SA</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

  </footer>

</article>

  </div>
  

<div class="post-nav">
    <div class="item left">
    </div>
    <div class="item right">
      

  <a href="/blog/2020/12/23/moti%E5%BC%80%E6%BA%90%E5%AD%A6%E5%88%B0%E7%9A%84/" itemprop="url" rel="next" data-background-image="https:&#x2F;&#x2F;tva4.sinaimg.cn&#x2F;mw690&#x2F;6833939bly1gipeu1usa7j20zk0m8b29.jpg" title="moti">
  <span class="type">下一篇</span>
  <span class="category"><i class="ic i-flag"></i> 开源项目笔记</span>
  <h3>moti</h3>
  </a>

    </div>
</div>

  
  <div class="wrap" id="comments"></div>


        </div>
        <div id="sidebar">
          

<div class="inner">

  <div class="panels">
    <div class="inner">
      <div class="contents panel pjax" data-title="文章目录">
          <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#maven%E5%BC%95%E5%85%A5"><span class="toc-number">1.</span> <span class="toc-text"> maven 引入</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%85%8D%E7%BD%AEdruid"><span class="toc-number">2.</span> <span class="toc-text"> 配置 Druid</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#springboot-config"><span class="toc-number">3.</span> <span class="toc-text"> springboot config</span></a></li></ol>
      </div>
      <div class="related panel pjax" data-title="系列文章">
        <ul>
          <li class="active"><a href="/blog/2020/12/23/Druid%E9%85%8D%E7%BD%AE/" rel="bookmark" title="Druid配置">Druid配置</a></li>
        </ul>
      </div>
      <div class="overview panel" data-title="站点概览">
        <div class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <img class="image" itemprop="image" alt="杜朝宇"
      data-src="/blog/images/touxiang.jpg">
  <p class="name" itemprop="name">杜朝宇</p>
  <div class="description" itemprop="description">个人博客&编程笔记</div>
</div>

<nav class="state">
    <div class="item posts">
      <a href="/blog/archives/">
        <span class="count">8</span>
        <span class="name">文章</span>
      </a>
    </div>
    <div class="item categories">
      <a href="/blog/categories/">
        <span class="count">4</span>
        <span class="name">分类</span>
      </a>
    </div>
    <div class="item tags">
      <a href="/blog/tags/">
        <span class="count">2</span>
        <span class="name">标签</span>
      </a>
    </div>
</nav>

<div class="social">
</div>

<ul class="menu">
  
    
  <li class="item">
    <a href="/blog/" rel="section"><i class="ic i-home"></i>首页</a>
  </li>

    
  <li class="item">
    <a href="/blog/about/" rel="section"><i class="ic i-user"></i>关于</a>
  </li>

        
  <li class="item dropdown">
      <a href="javascript:void(0);"><i class="ic i-feather"></i>文章</a>
    <ul class="submenu">

        
  <li class="item">
    <a href="/blog/archives/" rel="section"><i class="ic i-list-alt"></i>归档</a>
  </li>

        
  <li class="item">
    <a href="/blog/categories/" rel="section"><i class="ic i-th"></i>分类</a>
  </li>

        
  <li class="item">
    <a href="/blog/tags/" rel="section"><i class="ic i-tags"></i>标签</a>
  </li>

  </ul>
        
  <li class="item dropdown">
      <a href="javascript:void(0);"><i class="ic i-magic"></i>链环</a>
    <ul class="submenu">

        
  <li class="item">
    <a href="/blog/friends/" rel="section"><i class="ic i-heart"></i>友链</a>
  </li>

  </ul>

</ul>

      </div>
    </div>
  </div>

  <ul id="quick">
    <li class="prev pjax">
    </li>
    <li class="up"><i class="ic i-arrow-up"></i></li>
    <li class="down"><i class="ic i-arrow-down"></i></li>
    <li class="next pjax">
    </li>
    <li class="percent"></li>
  </ul>
</div>


        </div>
        <div class="dimmer"></div>
      </div>
    </main>
    <footer id="footer">
      <div class="inner">
        <div class="widgets">
          
<div class="rpost pjax">
  <h2>随机文章</h2>
  <ul>
      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/java/" title="分类于 java">java</a>
</div>

    <span><a href="/blog/2020/12/23/Druid%E9%85%8D%E7%BD%AE/" title="Druid配置">Druid配置</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/SpringCloud/" title="分类于 SpringCloud">SpringCloud</a>
</div>

    <span><a href="/blog/2020/12/24/gateway/" title="gateway">gateway</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/%E5%BC%80%E6%BA%90%E9%A1%B9%E7%9B%AE%E7%AC%94%E8%AE%B0/" title="分类于 开源项目笔记">开源项目笔记</a>
</div>

    <span><a href="/blog/2020/12/23/moti%E5%BC%80%E6%BA%90%E5%AD%A6%E5%88%B0%E7%9A%84/" title="moti">moti</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/SpringCloud/" title="分类于 SpringCloud">SpringCloud</a>
</div>

    <span><a href="/blog/2020/12/24/Spring%20Cloud%20Stream/" title="Spring Cloud Stream">Spring Cloud Stream</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/SpringCloud/" title="分类于 SpringCloud">SpringCloud</a>
</div>

    <span><a href="/blog/2020/12/24/Spring%20Cloud%20sleuth/" title="Spring Cloud sleuth">Spring Cloud sleuth</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/Spring-Cloud-Alibaba/" title="分类于 Spring Cloud Alibaba">Spring Cloud Alibaba</a>
</div>

    <span><a href="/blog/2020/12/24/Nacos/" title="Cloud Alibaba Nacos">Cloud Alibaba Nacos</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/SpringCloud/" title="分类于 SpringCloud">SpringCloud</a>
</div>

    <span><a href="/blog/2020/12/24/Hystrix/" title="Hystrix">Hystrix</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/SpringCloud/" title="分类于 SpringCloud">SpringCloud</a>
</div>

    <span><a href="/blog/2020/12/24/Spring%20Config+Bus/" title="Spring Config+Bus">Spring Config+Bus</a></span>
  </li>

  </ul>
</div>
<div>
  <h2>最新评论</h2>
  <ul class="leancloud-recent-comment"></ul>
</div>

        </div>
        <div class="status">
  <div class="copyright">
    
    &copy; 2010 – 
    <span itemprop="copyrightYear">2020</span>
    <span class="with-love">
      <i class="ic i-sakura rotate"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">杜朝宇 @ blog</span>
  </div>
  <div class="count">
    <span class="post-meta-item-icon">
      <i class="ic i-chart-area"></i>
    </span>
    <span title="站点总字数">42k 字</span>

    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="ic i-coffee"></i>
    </span>
    <span title="站点阅读时长">38 分钟</span>
  </div>
  <div class="powered-by">
    基于 <span class="exturl" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & Theme.<span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2FtZWhpbWUvaGV4by10aGVtZS1zaG9rYQ==">Shoka</span>
  </div>
</div>

      </div>
    </footer>
  </div>
<script data-config type="text/javascript">
  var LOCAL = {
    path: '2020/12/23/Druid配置/',
    favicon: {
      show: "（●´3｀●）やれやれだぜ",
      hide: "(´Д｀)大変だ！"
    },
    search : {
      placeholder: "文章搜索",
      empty: "关于 「 ${query} 」，什么也没搜到",
      stats: "${time} ms 内找到 ${hits} 条结果"
    },
    valine: true,fancybox: true,copyright: '复制成功，转载请遵守 <i class="ic i-creative-commons"></i>BY-NC-SA 协议。',
    ignores : [
      function(uri) {
        return uri.includes('#');
      },
      function(uri) {
        return new RegExp(LOCAL.path+"$").test(uri);
      }
    ]
  };
</script>

<script src="https://cdn.polyfill.io/v2/polyfill.js"></script>

<script src="//cdn.jsdelivr.net/combine/npm/pace-js@1.0.2/pace.min.js,npm/pjax@0.2.8/pjax.min.js,npm/whatwg-fetch@3.4.0/dist/fetch.umd.min.js,npm/animejs@3.2.0/lib/anime.min.js,npm/algoliasearch@4/dist/algoliasearch-lite.umd.js,npm/instantsearch.js@4/dist/instantsearch.production.min.js,npm/lozad@1/dist/lozad.min.js,npm/quicklink@2/dist/quicklink.umd.js"></script>

<script src="/blog/js/app.js?v=0.2.5"></script>




</body>
</html>
